package crack.four_point_test;

import math2.MathUtilities;
import crack.AbstractFourPointTestUsingSDAElementDemo;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.element.crack_sda.SKONConstantJumpCSTElementUsingRecoverStress;
import fem2.enu.State;
import fem2.material.SPRrecoveryMM;
import fem2.material.StVenantKirchhoffMM;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.material.cohesive_law.Mode1JirasekExponentialCohesiveLaw;
import fem2.strategies.ArcLengthSolutionStrategyWithDistanceConstraint;
import fem2.strategies.Strategy;

public class FourPointTestMesh6SKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw
		extends AbstractFourPointTestUsingSDAElementDemo {

	public FourPointTestMesh6SKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw() {
		meshFileName = "mesh6-skon-recover2-jirasek.msh";
		wp = 40;
		hp = 20;
		enableFixOnePointOnLeft = false;
		enableSlideOnePointOnRight = true;
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		double ft = 2.8;
		double Gf = 0.1;
		double Dnn = 1;
		double Dmm = 1;
		return new Mode1JirasekExponentialCohesiveLaw(Gf, ft, Dnn, Dmm);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		// Element e = new StructuralElement(mp, mm);
		// Element e = new SKONConstantJumpCSTElement(mp, mm, cl);
		Element e = new SKONConstantJumpCSTElementUsingRecoverStress(mp, mm, cl);
		return e;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		double E = 28.8e3;
		double nu = 0.18;
		double t = 156;
		State ss = State.PLANE_STRESS;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, t, 0, ss);
		return new SPRrecoveryMM(m, mm);
	}

	public MaterialModel createMaterial2(Model m) {
		// double E = 28.8e4;
		// double nu = 0.18;

		double E = 20e6;
		double nu = 0.3;

		double t = 156;
		State ss = State.PLANE_STRESS;
		MaterialModel mm = new StVenantKirchhoffMM(E, nu, t, 0, ss);
		return new SPRrecoveryMM(m, mm);
	}

	public Strategy createStrategy(Model m) {
		Node n1 = MeshUtilities.seekNode(m.getMesh(), 654.0, 0);
		Node n2 = MeshUtilities.seekNode(m.getMesh(), 668.0, 0);

		// fix one point on sliding
		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0149, 0.0001 },
		// new int[] { 1, 20 });
		// double[] dArray = LinAlgUtilities.createLambdaArray(
		// new double[] { 0.0149, 0.0001, 0.0005 }, new int[] { 1, 20, 50 });
		// double[] dArray = LinAlgUtilities.createLambdaArray(
		// new double[] { 0.0149, 0.0001, 0.0005 }, new int[] { 1, 20, 100 });
		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0149, 0.0001, 0.0005,
		// 0.001 }, new int[] { 1, 20, 100, 50 }); // notable result
		double[] dArray = MathUtilities.createLambdaArray(new double[] { 0.0149, 0.0001, 0.0005,
				0.001 }, new int[] { 1, 20, 100, 100 }); // notable result

		Strategy st = new ArcLengthSolutionStrategyWithDistanceConstraint(m, dArray, n1, n2);

		return st;
	}

	public static void main(String[] args) {
		AbstractStructuralCrackDemo demo = new FourPointTestMesh6SKONConstantJumpCSTElementRecover2AndJirasekExponentialCohesiveLaw();

		demo.run();
	}
}
